/**	
 * 模拟set函数设置对象，成功返回true，失败返回false
 * @param {Array} arrs
 * @param {Object} item
 * @param {String} key 相等值比较的键
 */
export function SetObject(arrs, item, key) {
	let pos = indexOf(arrs, key, item[key])
	if (pos === -1) {
		arrs.push(item)
		return [true, item, arrs.length - 1]
	} else {
		return [false, arrs[pos], pos]
	}
}

/**	
 * @param {Object} arrs
 * @param {Object} key
 * @param {Object} targetValue
 */
let indexOf = function(arrs, key, targetValue) {
	for (let i = 0; i < arrs.length; i++) {
		let item = arrs[i]
		if (targetValue === item[key]) {
			return i
		}
	}
	return -1
}
